package com.chenjj.scala.bibao

/**
  * 演示以函数作为参数，函数有多个参数
  */
object FunctionMutipleParam {

  /**
    *
    * @param array
    * @param intial
    * @param operation 函数接收2个Int类型的参数，返回值为Int
    * @return
    */
  def inject(array: Array[Int],intial:Int,operation:(Int,Int)=>Int):Int ={
    var carryOver = intial;

    array.foreach(element => { carryOver = operation(carryOver,element)})

    carryOver
  }


  def main(args: Array[String]): Unit = {

    //对数组求和
    println(inject(Array(1,2,3,4,5),0,(a,b) => {a+b}))

  }
}
